package lch.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import lch.dao.MemberDao;
import lch.dao.OrderDao;
import lch.dao.SetmealDao;
import lch.service.ReportService;
import lch.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lch
 * @date 2019-12-27 10:11
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
//                reportDate:null,
//                todayNewMember :0,
//                totalMember :0,
//                thisWeekNewMember :0,
//                thisMonthNewMember :0,
//                todayOrderNumber :0,
//                todayVisitsNumber :0,
//                thisWeekOrderNumber :0,
//                thisWeekVisitsNumber :0,
//                thisMonthOrderNumber :0,
//                thisMonthVisitsNumber :0,
//                hotSetmeal :[
//        {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
//        {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
//                 ]
        Map<String, Object> map = new HashMap<>();
        //获取当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //今日新会员
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //总会员
        Integer totalMember = memberDao.findMemberTotalCount();
        //本周新会员
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(DateUtils.parseDate2String(DateUtils.getThisWeekMonday()));
        //本月新会员
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth()));
        //今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //今日到诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(DateUtils.parseDate2String(DateUtils.getThisWeekMonday()));
        //本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(DateUtils.parseDate2String(DateUtils.getThisWeekMonday()));
        //本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth()));
        //本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth()));
        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();


        map.put("reportDate", today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
